//输入一个正整数 target ，输出所有和为 target 的连续正整数序列（至少含有两个数）。 
//
// 序列内的数字由小到大排列，不同序列按照首个数字从小到大排列。 
//
// 
//
// 示例 1： 
//
// 输入：target = 9
//输出：[[2,3,4],[4,5]]
// 
//
// 示例 2： 
//
// 输入：target = 15
//输出：[[1,2,3,4,5],[4,5,6],[7,8]]
// 
//
// 
//
// 限制： 
//
// 
// 1 <= target <= 10^5 
// 
//
// 
// 👍 246 👎 0


package leetcode.editor.cn;

import java.util.*;

//Java：和为s的连续正数序列
public class IIHeWeiSdeLianXuZhengShuXuLieLcof{
    public static void main(String[] args) {
        Solution solution = new IIHeWeiSdeLianXuZhengShuXuLieLcof().new Solution();
        StringBuilder stringBuilder = new StringBuilder("123");
        System.out.println(stringBuilder.length());
        stringBuilder.delete(0,5);
        System.out.println(stringBuilder.length());
        stringBuilder.append(stringBuilder);
        // TO TEST
        //Arrays.stream(solution.findContinuousSequence(9)).forEach(arr-> Arrays.stream(arr).forEach(value -> System.out.println(value)));

    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int[][] findContinuousSequence(int target) {
        Queue<Integer> queue = new LinkedList<>();
        int left = 1;
        int right = 2;
        int sum = 3;
        ArrayList<int[]> res = new ArrayList<>();
        while(left < right && right < target/2+2){
            if(sum<target){
                right++;
                sum = (left+right)*(right-left+1)/2;
            } else if(sum>target){
                left++;
                sum = (left+right)*(right-left+1)/2;
            } else{
                int[] arr = new int[right-left+1];
                for(int i = 0 , j = left; i < arr.length ; i++){
                    arr[i] = j++;
                }
                res.add(arr);
                left++;
                sum = (left+right)*(right-left+1)/2;
            }
        }
        return res.toArray(new int[res.size()][]);
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}